{include file=buyer.header.html}
<script type="text/javascript">
//<!CDATA[
$.validator.addMethod('checkZipcode', function(value) {
    var region_id = $('#region_id').val();
    return checkPostcode(value, region_id);
});

$.validator.addMethod('checkContact', function(value) {
    var v0 = $('#phone_section').val(),
        v1 = $('#phone_code').val(),
        v2 = $('#phone_ext').val();
    var go = true;
    if (value == '') {
        if (v0 == '' && v1 == '' && v2 == '') {
            go = false;
        }
    }
    return go;
}, '手机号码和电话号码不能同时为空');

$.validator.addMethod('isAreaEmpty', function() {
    var v0 = $('#phone_section').val(),
        v1 = $('#phone_code').val();
    return checkArea(v0, v1);
}, '区号不正确');

$.validator.addMethod('isTelEmpty', function() {
    var v0 = $('#phone_section').val(),
        v1 = $('#phone_code').val();
    return checkTel(v0, v1);
}, '电话号码不正确');

function checkPostcode(val, region_id) {
    if (val == '' || region_id == '3409') {
        return true; //如果是海外，邮政编码可以为空
    } else {
        var _reg = /^\d{6}$/;
        return _reg.test(val);
    }
}

function checkArea(v0, v1) {
    var phone_mob = $('#phone_mob').val();
    var go = true;
    var r0 = /^\d{3,4}$/;
    if (phone_mob != '') {
        if(v1 == ''){
            if(v0 == ''){
                go = true;
            }else if(v0 != '' && r0.test(v0)){
                go = true;
            }else{
                go=false;
            }
        }else{
            if(r0.test(v0)){
                go=true;
            }else{
                go=false;
            }
        }
    }else{
      if (r0.test(v0)) {
          go = true;
      } else {
          go = false;
      }
    }
    return go;
}

function checkTel(v0, v1) {
    var phone_mob = $('#phone_mob').val();
    var go = true;
    var r1 = /^\d{7,8}$/;
    if (phone_mob != '') {
        if(v0 == ''){
            if(v1 == ''){
                go = true;
            }else if(v1 != '' && r1.test(v1)){
                go = true;
            }else{
                go=false;
            }
        }else{
            if(r1.test(v1)){
                go=true;
            }else{
                go=false;
            }
        }
    }else{
      if (r1.test(v1)) {
          go = true;
      } else {
          go = false;
      }
    }
    return go;
}

$(function(){
    regionInit("region");
    $('#address_form').validate({
        errorLabelContainer: $('#warning'),
        onkeyup : false,
        rules : {
            consignee : {
                required : true,
                checkRealname : true 
            },
            region_id : {
                countSelect : true
            },
            address : {
                required : true
            },
            zipcode : {
                checkZipcode : true
            },
            phone_mob : {
                checkContact : true,
                isMobile : true
            },
            phone_section :{
                isAreaEmpty : true
            },
            phone_code : {
                isTelEmpty : true
            }
        },
        messages : {
            consignee : {
                required : '{$lang.consignee_required}. ',
                checkRealname : '收货人姓名由中英文组成，1-20个字符'
            },
            address : {
                required : '{$lang.address_required}. '
            },
            zipcode : {
                checkZipcode : '邮政编码错误. '
            }
        }
    });
});
//]]>
</script>
<!-- 内容 -->
<div class="content f-cb">
		<!-- 当前位置 -->
		{include file=path.html}
		<!-- 内容左边栏 -->
		{include file=member.menu.buyer.html}
		<!-- 内容右边栏 -->
		<div class="con-receive-r">
        <div class="receive-panes">
          <div class="receive-panes-d">
            <dl class="f-bb1">
              <dt> 已保存的收货地址 <span>( 最多保存10个有效地址 )</span>
              <dd class="seller_address_dx">
                <table width="100%" class="receive-table">
                <!--{if $addresses_list}-->
                  <tr class="receive-tr">
                        <th width="100">{$lang.consignee}</th>
                        <th width="180">{$lang.region}</th>
                        <th width="240">{$lang.address}</th>
                        <th width="120">{$lang.zipcode}</th>
                        <th width="100">{$lang.phone}</th>
                        <th>{$lang.handle}</th>
                  </tr>
                  <!--{/if}-->
                  <!--{foreach from=$addresses_list item=addresses name=v}-->
                       <tr class="receive-tr">
                        <td><p>{$addresses.consignee|escape}</p></td>
                        <td><p>{$addresses.region_name|escape}</p></td>
                        <td><p>{$addresses.address|escape}</p></td>
                        <td><p>{$addresses.zipcode|escape}</p></td>
                        <td><p>{$addresses.phone_tel} <!--{if $addresses.phone_tel}--><br /><!--{/if}-->{$addresses.phone_mob}</p></td>
                        <td><a class="linkbtn" href="index.php?app=my_address&act_type=edit&addr_id={$addresses.addr_id}#here" class="edit1 float_none">{$lang.edit}</a> <br />
                        <!--{if $addresses.is_deafult eq 0}--> <a class="linkbtn" href="index.php?app=my_address&act=setdefault&addr_id={$addresses.addr_id}" title="{$lang.set_default}" class="float_none">{$lang.set_default}</a><!--{else}--> {$lang.default_address}
                         <!--{/if}--><br />
                            <a class="linkbtn" href="javascript:drop_confirm('{$lang.drop_confirm}', 'index.php?app=my_address&act=drop&addr_id={$addresses.addr_id}');" class="delete float_none">{$lang.drop}</a>
                        </td>
                    </tr>
                    <!--{foreachelse}-->
                    <tr>
                        <td colspan="6" class="member_no_records padding6">{$lang.no_records}</td>
                    </tr>
                    <!--{/foreach}-->
                    
                </table>
              </dd>
              </dt>
            </dl>
            <dl>
              <div class="dialog_content" style="margin: 0px; padding: 0px;">
              <a name="here"></a>
                <ul class="tab">
                  <li class="active"><!--{if $address.addr_id}-->{$lang.edit_consignee_successed}<!--{else}-->{$lang.add_consignee_address}<!--{/if}--></li>
                </ul>
                <div class="eject_con">
                <div class="add">
                    <div id="warning"></div>
                    <form method="post" action="index.php?app=my_address&act={$act}&addr_id={$address.addr_id}" id="address_form" >
                    <ul>
                        <li>
                            <h3><i>*</i> {$lang.consignee}: </h3>
                            <p><input type="text" class="text width_normal b-radius" name="consignee" maxlength="20"  value="{$address.consignee|escape}" /></p>
                        </li>
                        <li>
                            <h3><i>*</i> {$lang.region}: </h3>
                            <p id="region">
                                        <input type="hidden" name="region_id" value="{$address.region_id}" id="region_id" class="mls_id" />
                                        <input type="hidden" name="region_name" value="{$address.region_name|escape}" class="mls_names" />
                                        <!-- {if $address.region_id} -->
                                        <span>{$address.region_name|escape}</span>
                                        <input type="button" value="{$lang.edit}" class="edit_region" />
                                        <select style="display:none">
                                          <option>{$lang.select_pls}</option>
                                          {html_options options=$regions}
                                        </select>
                                        <!-- {else} -->
                                        <select>
                                          <option>{$lang.select_pls}</option>
                                          {html_options options=$regions}
                                        </select>
                                        <!-- {/if} -->
                                        <b class="field_message" style="font-weight:normal;"><label class="field_notice"></label></b>
                            </p>
                        </li>
                        <li>
                            <h3><i>*</i> {$lang.address}: </h3>
                            <p><input type="text" class="text width_normal b-radius" name="address" maxlength="50" placeholder="{$lang.address_desc}" value="{$address.address|escape}" /></p>
                        </li>
                        <li>
                            <h3><i>&nbsp;</i> {$lang.zipcode}: </h3>
                            <p><input type="text" class="text width_normal b-radius" name="zipcode" value="{$address.zipcode|escape}" maxlength="6" onkeyup="this.value=this.value.replace(/\D/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" /><label class="field_message"><span class="field_notice"></span></label></p>
                        </li>
                        <li>
                            <h3><i>&nbsp;</i> {$lang.phone_mob}:</h3>
                            <p><input type="text" class="text width_normal b-radius" name="phone_mob" id="phone_mob" placeholder="电话号码、手机号码必须填一项" value="{$address.phone_mob}" maxlength="11" onkeyup="this.value=this.value.replace(/\D/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"/></p>
                        </li>
                        <li>
                            <h3><i>&nbsp;</i> {$lang.phone_tel}:</h3>
                            <p><input type="text" class="text width4 b-radius" name="phone_section" placeholder="区号" value="{$phone_tel.0}" maxlength="4" id="phone_section" onkeyup="this.value=this.value.replace(/\D/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" />&nbsp;-&nbsp;<input type="text" class="text w100 b-radius" name="phone_code" placeholder="电话号码" value="{$phone_tel.1}" id="phone_code" maxlength="8" onkeyup="this.value=this.value.replace(/\D/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" />&nbsp;-&nbsp;<input type="text" class="text width4 b-radius" name="phone_ext" placeholder="分机" value="{$phone_tel.2}" id="phone_ext" maxlength="6" onkeyup="this.value=this.value.replace(/\D/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" /></p>
                        </li>                      
                        <li><h3><i>&nbsp;</i> {$lang.set_default}:</h3><p><input type="checkbox" class="check" <!--{if $address.is_deafult eq 1}--> checked="checked" <!--{/if}--> name="default" id="default" value="1"><span class="bold">{$lang.set_consignee_default}</span></p>
                        </li>
                    </ul>
                    <div class="submit"><input type="hidden" name="type" value="1" /><input type="submit" class="btn b-radius" value="<!--{if $address.addr_id}-->{$lang.edit_address}<!--{else}-->{$lang.add_address}<!--{/if}-->" />&nbsp;&nbsp;<!--{if $address.addr_id}--><input type="button" class="btn b-radius" value="{$lang.add_address}"  onclick="location.href='index.php?app=my_address#here'" /> <!--{/if}--></div>
                    </form>
                </div>
                </div>
              </div>
            </dl>
          </div>
        </div>
      </div>
	</div>
    <!-- 页脚 -->
{include file=footer.html}